//
//  ProgressView.m
//  progressView
//
//  Created by 李松 on 2017/11/20.
//  Copyright © 2017年 李松. All rights reserved.
//

#import "ProgressView.h"

@implementation ProgressView


//重写set方法
- (void)setProgressValue:(CGFloat)progressValue{
    _progressValue = progressValue;
    
    //手动调用此方法, 不会自动创建上下文, 只有系统调用时才能创建上下文
//    [self drawRect:self.bounds];
    [self setNeedsDisplay];
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
    
//    //1.获取上下文
//    CGContextRef ctx = UIGraphicsGetCurrentContext();
//    //2.描述路径
//
    CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);
    CGFloat radius = rect.size.width * 0.5 - 10;

    //开始角度
    CGFloat startAngle = -M_PI_2;

    CGFloat tempAngle = self.progressValue * M_PI * 2;

    CGFloat endAngle = startAngle + tempAngle;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
    [path setLineWidth:5];
    [path stroke];
//
//    //3.把路径添加到上下文中
//    CGContextAddPath(ctx, path.CGPath);
//
//    //4.把上下文的内容渲染到view的layer上
//    CGContextStrokePath(ctx);
}


@end
